﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Client-Server Sync Tests</title>
		
		<link href="../Common/Styles/qunit.css" type="text/css" rel="stylesheet" />
		
		<script src="../Common/Scripts/JQuery/jquery-1.3.2.js" type="text/javascript"></script>
		<script src="../Common/Scripts/QUnit/qunit.js" type="text/javascript"></script>
		<script src="../Common/Scripts/Microsoft/MicrosoftAjax.js" type="text/javascript"></script>
		<script src="../Common/Scripts/ExoWeb/exoweb.js" type="text/javascript"></script>
		<script src="../Common/Scripts/QUnit/qunit.ext.js" type="text/javascript"></script>
		<script src="../Common/Scripts/ExoWeb/exoweb.model.js" type="text/javascript"></script>
		<script src="../Common/Scripts/ExoWeb/exoweb.mapper.js" type="text/javascript"></script>
		<script src="../Common/Scripts/ExoWeb/exoweb.mock.js" type="text/javascript"></script>
		<script src="../Common/Scripts/mock-driver.js" type="text/javascript"></script>
		<script src="ChangeSet.js" type="text/javascript"></script>
		
		<script type="text/javascript">
			ExoWeb.Mock.objectProviderDelay = 0;
			ExoWeb.Mock.typeProviderDelay = 0;
			ExoWeb.Mock.roundtripProviderDelay = 0;
			ExoWeb.Mock.simulateLazyLoading = true;

			// HACK: signal behavior that temporarily releases control conflicts with synchronous nature of tests
			ExoWeb.Signal.prototype._doCallback = function Signal$_doCallback(name, thisPtr, callback, args) {
				try {
					callback.apply(thisPtr, args || []);
				}
				catch (e) {
					ExoWeb.trace.logError("signal", "({0}) {1} callback threw an exception: {2}", [this._debugLabel, name, e]);
				}
			};

			var context = ExoWeb.context({ model: { driver: { id: "1", from: "Driver", and: ["this.PrimaryCar.OriginalOwner", "this.Dealer.AvailableCars" ] }} });

			setupTest("test1", { description: "All relevant properties for items in a list should be loaded when list is lazy loaded." }, function () {
				var undefined;

				ok(ExoWeb.Model.LazyLoader.isLoaded(context.model.driver.get_PrimaryCar()), "Primary Car property should be loaded.");
				ok(ExoWeb.Model.LazyLoader.isLoaded(context.model.driver.get_PrimaryCar().get_OriginalOwner()), "Original Owner property of Primary Car should be loaded.");
				ok(!ExoWeb.Model.LazyLoader.isLoaded(context.model.driver.get_Cars()), "Cars property should NOT be loaded.");

				ExoWeb.Model.LazyLoader.eval(context.model.driver, "Cars", function () {
					Array.forEach(context.model.driver.get_Cars(), function (car) {
						ok(ExoWeb.Model.LazyLoader.isLoaded(car.get_OriginalOwner()), "Original Owner property of each Car should be loaded.");
					});
				});
			});

			timeoutTests(5000);

			context.ready(function () {
				executeTest("test1");
			});
		</script>
	</head>
	<body xmlns:sys="javascript:Sys" xmlns:dataview="javascript:Sys.UI.DataView" sys:activate="*">
		
		<!-- QUnit Display -->
		<h1 id="qunit-header">Test Results:</h1>
		<h2 id="qunit-banner"></h2>
		<h2 id="qunit-userAgent"></h2>
		<ol id="qunit-tests"></ol>
	</body>
</html>
